<?php
	class Cartelera{


		private $id_cartelera;
		private $imagen;
		private $titulo;
		private $descripcion_1;
		private $descripcion_2;
		private $dias;
		private $hora;
		private $lugar;
		private $entradas;

		public function __construct($id = 0){
			$this->id_cartelera = $id;
			if($this->id_cartelera > 0){
				$sql = "SELECT * FROM carteleras WHERE id_cartelera = ".$id;
				$qry = new Consulta($sql);
				if($qry->NumeroRegistros() > 0){
					$rw = $qry->VerRegistro();
					$this->imagen 					= $rw['imagen'];
					$this->titulo			 		= $rw['titulo'];
					$this->descripcion_1	 		= $rw['descripcion_1'];
					$this->descripcion_2 			= $rw['descripcion_2'];
					$this->dias					 	= $rw['dias'];
					$this->hora					 	= $rw['hora'];
					$this->lugar			 		= $rw['lugar'];
					$this->entradas			 		= $rw['entradas'];
				}					
			}
		}


		public function __get($atributo){
			return $this->$atributo;
		}


		public function getCarteleras(){
			$sql = "SELECT * FROM carteleras ORDER BY id_cartelera DESC";
			$qry = new Consulta($sql);
			while( $rw = $qry->VerRegistro() ){
				$rst[] = array(
					'id'				=> $rw['id_cartelera'],
					'imagen'			=> $rw['imagen'],
					'titulo'			=> $rw['titulo'],
					'descripcion_1'		=> $rw['descripcion_1'],
					'descripcion_2'		=> $rw['descripcion_2'],
					'dias'				=> $rw['dias'],
					'hora'				=> $rw['hora'],
					'lugar'				=> $rw['lugar'],
					'entradas'			=> $rw['entradas']
				);
			}
			return $rst;			
		}

		public function getCartelerasLimit($ini, $num_reg){
			$sql = "SELECT * FROM carteleras ORDER BY id_cartelera DESC LIMIT ".$ini.",".$num_reg."";
			$query = new Consulta($sql);
			while( $rw = $query->VerRegistro() ){
				$result[] = array(
					'id'				=> $rw['id_cartelera'],
					'imagen'			=> $rw['imagen'],
					'titulo'			=> $rw['titulo'],
					'descripcion_1'		=> $rw['descripcion_1'],
					'descripcion_2'		=> $rw['descripcion_2'],
					'dias'				=> $rw['dias'],
					'hora'				=> $rw['hora'],
					'lugar'				=> $rw['lugar'],
					'entradas'			=> $rw['entradas']
				);
			}
			return $result;		
		}

		public function getCarteleraRand(){
			$sql = "SELECT * FROM carteleras ORDER BY RAND() LIMIT 1";
			$query = new Consulta($sql);
			while( $rw = $query->VerRegistro() ){
				$result[] = array(
					'id'				=> $rw['id_cartelera'],
					'imagen'			=> $rw['imagen'],
					'titulo'			=> $rw['titulo'],
					'descripcion_1'		=> $rw['descripcion_1'],
					'descripcion_2'		=> $rw['descripcion_2'],
					'dias'				=> $rw['dias'],
					'hora'				=> $rw['hora'],
					'lugar'				=> $rw['lugar'],
					'entradas'			=> $rw['entradas']
				);
			}
			return $result;		
		}


	}
?>